package com.ktjy.crm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktjy.crm.entity.SysUser;
import com.ktjy.crm.mapper.SysUserMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Resource
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser login(String account, String password) {
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account", account);
        queryWrapper.eq("password", password);
        SysUser sysUser = sysUserMapper.selectOne(queryWrapper);
        return sysUser;
    }

    @Override
    public Page selectPage(Integer current, Integer size) {
        QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
        Page<SysUser> page = new Page<>(current, size);
        Page<SysUser> sysUserPage = sysUserMapper.selectPage(page, wrapper);
        return sysUserPage;
    }

    @Override
    public SysUser selectById(Integer id) {
        SysUser sysUser = sysUserMapper.selectById(id);
        return sysUser;
    }

    @Override
    public int deleteById(Integer id) {
        int num = sysUserMapper.deleteById(id);
        return num;
    }

    @Override
    public int updateById(SysUser sysUser) {
        int num = sysUserMapper.updateById(sysUser);
        return num;
    }

    @Override
    public int insert(SysUser sysUser) {
        int num = sysUserMapper.insert(sysUser);
        return num;
    }

    @Override
    public Page<SysUser> selectPageByName(String realName, Integer current, Integer size) {
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("realName", realName);
        Page<SysUser> page = new Page<>(current, size);
        return sysUserMapper.selectPage(page, queryWrapper);
    }
}
